﻿using System;

using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Silvermoon.Controls.Classes
{
    /// <summary>
    /// Collection class for TreeView Items.
    /// </summary>
    public class TreeViewItemCollection : BindingList<ItemBase>
    {
        private TreeViewItem owner;

        public TreeViewItemCollection(TreeViewItem owner)
            : base()
        {
            this.owner = owner;
        }

        protected override void InsertItem(int index, ItemBase item)
        {
            TreeViewItem tvi = item as TreeViewItem;
            if (tvi != null) tvi.ParentItem = owner;
            base.InsertItem(index, item);
        }

        protected override void RemoveItem(int index)
        {
            TreeViewItem item = this[index] as TreeViewItem;
            if (item != null) item.ParentItem = null;
            base.RemoveItem(index);
        }
    }
}
